/**************************************************************************************************
 * red library                                                                                    *
 * Copyright © 2012 David Kretzmer                                                                *
 *                                                                                                *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software  *
 * and associated documentation files (the "Software"), to deal in the Software without           *
 * restriction,including without limitation the rights to use, copy, modify, merge, publish,      *
 * distribute,sublicense, and/or sell copies of the Software, and to permit persons to whom the   *
 * Software is furnished to do so, subject to the following conditions:                           *
 *                                                                                                *
 * The above copyright notice and this permission notice shall be included in all copies or       *
 * substantial portions of the Software.                                                          *
 *                                                                                                *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING  *
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND     *
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.        *
 *                                                                                                *
 *************************************************************************************************/

#pragma once

#include "red/static_vector_base.hpp"

#include <vector>


namespace red
{
	//=============================================================================================
	// Vector with dynamic size
	//=============================================================================================
	template<typename Real>
	class dynamic_vector
	{
	public:
		typedef Real real_type;
		static bool const is_static = false;

		dynamic_vector() = default;

		dynamic_vector(size_t element_count) :
			m_components(element_count)
		{

		}

		dynamic_vector(dynamic_vector const &rhs) :
			m_components(rhs.m_components)
		{

		}

		dynamic_vector(dynamic_vector &&rhs) :
			m_components(::std::move(rhs.m_components))
		{

		}

		real_type const& element_at(size_t index) const
		{
			assert(index < dimension());
			return m_components[index];
		}

		real_type& element_at(size_t index)
		{
			assert(index < dimension());
			return m_components[index];
		}

		real_type const& operator [] (size_t index) const
		{
			return element_at(index);
		}

		real_type& operator [] (size_t index)
		{
			return element_at(index);
		}

		size_t dimension() const { return m_components.size(); }

	private:
		::std::vector<real_type> m_components;
	};


	//=============================================================================================
	// Make it a valid vector
	//=============================================================================================
	template<typename Real>
	struct is_vector<dynamic_vector<Real> >
	{
		static bool const value = true;
	};

} // namespace: red
